package com.game.hall;

import com.game.message.messagecode.DubboMsg;
import com.game.message.messagecode.GameServerMsgStage;
import com.game.message.messagecode.HallMsg;
import com.game.messagebean.hall.LoginReq;
import com.game.messagebean.dubbo.RechargeReq;
import com.game.messagebean.dubbo.UserInfoReq;
import com.game.net.client.jpbsocket.JPbSocketNettyClient;
import com.game.message.jpb.JPbUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by legend9999 on 2016/6/5.
 */
public class HallClient {

    public static void main(String[] args) throws Exception {
        final ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
        for (int i = 0; i < 1; i++) {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        final JPbSocketNettyClient nettyClient = ac.getBean(JPbSocketNettyClient.class);
                        nettyClient.init("127.0.0.1", 9001);


                        LoginReq loginReq = new LoginReq();
                        loginReq.setMsgId(HallMsg.LOGIN);
                        loginReq.setLoginName("aaa");
                        loginReq.setPassword("bbb");
                        loginReq.setGameId(GameServerMsgStage.JINHUA);
                        nettyClient.write(JPbUtil.getMsg(LoginReq.class, loginReq));

                        RechargeReq rechargeReq = new RechargeReq();
                        rechargeReq.setMsgId(DubboMsg.Recharge);
                        rechargeReq.setYuanbao(11111);
                        nettyClient.write(JPbUtil.getMsg(RechargeReq.class, rechargeReq));

                        UserInfoReq userInfoReq = new UserInfoReq();
                        userInfoReq.setMsgId(DubboMsg.UserInfo);
                        while (true) {
                            Thread.sleep(1000);
                            nettyClient.write(JPbUtil.getMsg(UserInfoReq.class, userInfoReq));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }
    }
}


